﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using System.Configuration;

namespace EF4.Core.IoC.Adapters
{
    public class  UnityServiceLocator : ServiceLocatorImplBase
    {

        private IUnityContainer container;


        public UnityServiceLocator() {

            container = new UnityContainer();
            UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
            section.Containers["EF4Container"].Configure(container);
            
        }

        public UnityServiceLocator(IUnityContainer container)
        {


            this.container = container;

        }

        protected override object DoGetInstance(Type serviceType, string key)
        {

            return this.container.Resolve(serviceType, key);

        }



        protected override IEnumerable<object> DoGetAllInstances(Type serviceType)
        {

            return this.container.ResolveAll(serviceType);

        }

    }

 
}
